<?php
	session_start();
	if(isset($_GET['pid'])){
		$qty = $_POST['s_quantity'];
		$id = $_GET['pid'];
		$db = new Model_mcart;
		$data = $db->add_cart($id);
		$_SESSION['cart'][$id]['name'] = $data['pro_name'];
		$_SESSION['cart'][$id]['id'] = $data['pro_id'];
		if(isset($_SESSION['cart'][$id]['qty'])){
			if(isset($_POST['s_quantity']) && $_POST['s_quantity'] != NULL){
				$_SESSION['cart'][$id]['qty'] = $_SESSION['cart'][$id]['qty']+ $qty;
			}else{
				$_SESSION['cart'][$id]['qty'] = $_SESSION['cart'][$id]['qty']+1;
			}
		}else{
			if(isset($_POST['s_quantity']) && $_POST['s_quantity'] != NULL){
				$_SESSION['cart'][$id]['qty'] = $qty;
			}else{
				$_SESSION['cart'][$id]['qty'] = 1;
			}
		}
		$_SESSION['cart'][$id]['price'] = $data['pro_price'];
		$_SESSION['cart'][$id]['images'] = $data['pro_images'];
		$_SESSION['cart'][$id]['rewrite'] = $data['pro_name_rewrite'];
		redirect("gio-hang");
	}else{
		die("Vui lòng chọn sản phẩm bạn muốn mua !");
	}
?>